let html = `<h1 id="contributing">Contributing to Nix</h1>
<p>Welcome and thank you for your interest in contributing to Nix! We appreciate your support.</p>
<p>Reading and following these guidelines will help us make the contribution process easy and effective for everyone
involved.</p>
<h2 id="report-a-bug">Report a bug</h2>
<ol>
<li><p>Check on the <a href="https://github.com/NixOS/nix/issues">GitHub issue tracker</a> if your bug was already reported.</p>
</li>
<li><p>If you were not able to find the bug or feature <a href="https://github.com/NixOS/nix/issues/new/choose">open a new issue</a></p>
</li>
<li><p>The issue templates will guide you in specifying your issue. The more complete the information you provide, the more
likely it can be found by others and the more useful it is in the future. Make sure reported bugs can be reproduced
easily.</p>
</li>
<li><p>Once submitted, do not expect issues to be picked up or solved right away. The only way to ensure this, is to
<a href="#making-changes-to-nix">work on the issue yourself</a>.</p>
</li>
</ol>
<h2 id="report-a-security-vulnerability">Report a security vulnerability</h2>
<p>Check out the <a href="https://github.com/NixOS/nix/security/policy">security policy</a>.</p>
<h2 id="making-changes-to-nix">Making changes to Nix</h2>
<ol>
<li><p>Search for related issues that cover what you&#39;re going to work on. It could help to mention there that you will work
on the issue.</p>
<p>We strongly recommend first-time contributors not to propose new features but rather fix tightly-scoped problems in
order to build trust and a working relationship with maintainers.</p>
<p>Issues labeled <a href="https://github.com/NixOS/nix/labels/good%20first%20issue">good first issue</a> should be relatively easy
to fix and are likely to get merged quickly. Pull requests addressing issues labeled
<a href="https://github.com/NixOS/nix/labels/idea%20approved">idea approved</a> or
<a href="https://github.com/NixOS/nix/labels/RFC">RFC</a> are especially welcomed by maintainers and will receive prioritised
review.</p>
<p>If you are proficient with C++, addressing one of the
<a href="https://github.com/NixOS/nix/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc">popular issues</a> will be
highly appreciated by maintainers and Nix users all over the world. For far-reaching changes, please investigate
possible blockers and design implications, and coordinate with maintainers before investing too much time in writing
code that may not end up getting merged.</p>
<p>If there is no relevant issue yet and you&#39;re not sure whether your change is likely to be accepted,
<a href="https://github.com/NixOS/nix/issues/new/choose">open an issue</a> yourself.</p>
</li>
<li><p>Check for <a href="https://github.com/NixOS/nix/pulls">pull requests</a> that might already cover the contribution you are about
to make. There are many open pull requests that might already do what you intend to work on. You can use
<a href="https://github.com/NixOS/nix/labels">labels</a> to filter for relevant topics.</p>
</li>
<li><p>Check the <a href="https://nix.dev/manual/nix/development/development/building.html">Nix reference manual</a> for information on
building Nix and running its tests.</p>
<p>For contributions to the command line interface, please check the
<a href="https://nix.dev/manual/nix/development/development/cli-guideline.html">CLI guidelines</a>.</p>
</li>
<li><p>Make your change!</p>
</li>
<li><p><a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request">Create a pull request</a>
for your changes.</p>
<ul>
<li><p>Clearly explain the problem that you&#39;re solving.</p>
<p>Link related issues to inform interested parties and future contributors about your change. If your pull request
closes one or multiple issues, mention that in the description using <code>Closes: #&lt;number&gt;</code>, as it will then happen
automatically when your change is merged.</p>
</li>
<li><p>Make sure to have
<a href="https://www.digitalocean.com/community/tutorials/how-to-rebase-and-update-a-pull-request">a clean history of commits on your branch by using rebase</a>.</p>
</li>
<li><p><a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request">Mark the pull request as draft</a>
if you&#39;re not done with the changes.</p>
</li>
</ul>
</li>
<li><p>Do not expect your pull request to be reviewed immediately. Nix maintainers follow a
<a href="https://github.com/NixOS/nix/tree/master/maintainers#project-board-protocol">structured process for reviews and design decisions</a>,
which may or may not prioritise your work.</p>
<p>Following this checklist will make the process smoother for everyone:</p>
<ul>
<li><input disabled="" type="checkbox"> Fixes an <a href="https://github.com/NixOS/nix/labels/idea%20approved">idea approved</a> issue</li>
<li><input disabled="" type="checkbox"> Tests, as appropriate:<ul>
<li>Functional tests – <a href="./tests/functional"><code>tests/functional/**.sh</code></a></li>
<li>Unit tests – <a href="./src/"><code>src/*/tests</code></a></li>
<li>Integration tests – <a href="./tests/nixos"><code>tests/nixos/*</code></a></li>
</ul>
</li>
<li><input disabled="" type="checkbox"> User documentation in the <a href="./doc/manual/src">manual</a></li>
<li><input disabled="" type="checkbox"> API documentation in header files</li>
<li><input disabled="" type="checkbox"> Code and comments are self-explanatory</li>
<li><input disabled="" type="checkbox"> Commit message explains <strong>why</strong> the change was made</li>
<li><input disabled="" type="checkbox"> New feature or incompatible change:
<a href="https://nix.dev/manual/nix/development/development/contributing.html#add-a-release-note">add a release note</a></li>
</ul>
</li>
<li><p>If you need additional feedback or help to getting pull request into shape, ask other contributors using
<a href="https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#mentioning-people-and-teams">@mentions</a>.</p>
</li>
</ol>
<h2 id="making-changes-to-the-nix-manual">Making changes to the Nix manual</h2>
<p>The Nix reference manual is hosted on <a href="https://nixos.org/manual/nix">https://nixos.org/manual/nix</a>. The underlying source files are located in
<a href="./doc/manual/src"><code>doc/manual/src</code></a>. For small changes you can
<a href="https://docs.github.com/en/repositories/working-with-files/managing-files/editing-files">use GitHub to edit these files</a>
For larger changes see the <a href="https://nix.dev/manual/nix/development/development/contributing.html">Nix reference manual</a>.</p>
<h2 id="getting-help">Getting help</h2>
<p>Whenever you&#39;re stuck or do not know how to proceed, you can always ask for help. The appropriate channels to do so can
be found on the <a href="https://nixos.org/community/">NixOS Community</a> page.</p>
<p><code>please accept this pull Request</code> <code>please accept this pull Request</code></p>
<pre><code class="language-python">def test():
    print()
    return 1


print(test() )
</code></pre>
<ul>
<li><input disabled="" type="checkbox"> <code>please accept this pull Request</code></li>
<li>please accept this pull Request</li>
</ul>
<ul>
<li>please accept this pull Request</li>
</ul>
<ul>
<li>please accept this pull Request</li>
</ul>
<pre><code class="language-C++">//实现红黑树 和B树
#include &lt;iostream&gt;
using namespace std;

int main() {
    cout &lt;&lt; &quot;Hello, World!&quot; &lt;&lt; endl;
    return 0;
}
</code></pre>
<pre><code class="language-javascript">console.log(&#39;hello world&#39;);
// 归并排序
function mergeSort(arr) {
    if (arr.length &lt; 2) {
        return arr;
    }
    const mid = Math.floor(arr.length / 2);
    const left = arr.slice(0, mid);
    const right = arr.slice(mid);
    return merge(mergeSort(left), mergeSort(right));
}

function merge(left, right) {
    let result = [];
    while (left.length &amp;&amp; right.length) {
        if (left[0] &lt;= right[0]) {
            result.push(left.shift());
        } else {
            result.push(right.shift());
        }
    }
    return result.concat(left, right);
}

const arr = [5, 3, 8, 4, 2];
const sortedArr = mergeSort(arr);
console.log(sortedArr); // 输出: [2, 3, 4, 5, 8]
</code></pre>
<pre><code class="language-go">package main

import &quot;fmt&quot;
//红黑树

type TreeNode struct {
    Color    bool
    Key      int
    Left     *TreeNode
    Right    *TreeNode
    Parent   *TreeNode
}


func main() {
    fmt.Println(&quot;Hello, World!&quot;)
}
</code></pre>
<pre><code class="language-java">public class Main {
    public static void main(String[] args) {
        System.out.println(&quot;Hello, World!&quot;);
    }
}
</code></pre>
<pre><code class="language-c">#include &lt;stdio.h&gt;

int main() {
    printf(&quot;Hello, World!\n&quot;);
    return 0;
}
</code></pre>
<pre><code class="language-rust">fn main() {
    println!(&quot;Hello, World!&quot;);
}
</code></pre>
<pre><code class="language-php">&lt;?php
echo &quot;Hello, World!&quot;;
?&gt;
</code></pre>
<pre><code class="language-ruby"> aa = &quot;Hello, World!&quot;
puts &quot;Hello, World!&quot;
</code></pre>
<pre><code class="language-shell">
echo &quot;Hello, World!&quot;
if [ -d &quot;/etc&quot; ]; then
    echo &quot;/etc exists&quot;
else
    echo &quot;/etc does not exist&quot;
fi
</code></pre>
 `;

let cheerio = require('cheerio');

// 提取 HTML 中的文本内容
function extractTextContent(html) {
	const $ = cheerio.load(html);
	let count = 0;
	// 移除<pre><code>标签中的内容
	$('pre').remove();
	$('pre code').remove();
	// 提取剩余文本内容
	let text = '';
	// $('body')
	// 	.children()
	// 	.each(function () {
	// 		$(this)
	// 			.contents()
	// 			.each(function () {
	// 				if (!$(this).is('pre') && !$(this).find('code').length && !$(this).is('\n')) {
	// 					text += $(this).text().trim() + '@';
	// 				}
	// 			});
	// 	});
	let first = true;
	$('body')
		.find('*')
		.each(function () {
			const tagName = this.tagName.toLowerCase();
			if (tagName !== 'pre' && tagName !== 'code') {
				$(this)
					.contents()
					.each(function () {
						if (this.type === 'text') {
							// 获取文本内容并移除换行符
							let content = $(this).text().replace(/\s+/g, ' ').trim();
							if (content !== '' && !!content) {
								if (!first) {
									text += '@';
								}
								text += content;
								first = false;
							}
						}
					});
			}
		});
	// console.log(text);
	return text.endsWith('@') ? text.slice(0, -1) : text;
}

// 模拟翻译函数
function translateText(text) {
	let result = text.split('@');
	let re = ``;
	for (let i = 0; i < result.length; i++) {
		result[i] = '翻译后的文本' + i;
		re += result[i] + '@';
	}
	// console.log(re);
	return re; // 这里只是示例，实际翻译后的文本应该返回
}

// 替换 HTML 中的文本
function replaceTextInHtml(html, translatedText) {
	const $ = cheerio.load(html);
	const translatedTexts = translatedText.split('@');
	let index = 0;
	$('body') //body避免把\n当做标签元素遍历
		.find('*')
		.each(function () {
			const tagName = this.tagName.toLowerCase();
			if (tagName !== 'pre' && tagName !== 'code') {
				$(this)
					.contents()
					.each(function () {
						if (this.type === 'text') {
							const text = $(this).text().replace(/\s+/g, ' ').trim();
							if (text) {
								$(this).replaceWith(translatedTexts[index]);
								index++;
							}
						}
					});
			}
		});
	console.log($.html());
	return $.html();
}

const textContent = extractTextContent(html);
const translatedText = translateText(textContent);
const resultHtml = replaceTextInHtml(html, translatedText);
